/*
 * Commandline.cpp
 *
 *  Created on: May 11, 2012
 *      Author: pleun
 */

#include "Commandline.h"

Commandline::Commandline() {
	words = new vector<string> ();
	containsAppend = false;
	containsInput = false;
	containsOutput = false;

}

Commandline::~Commandline() {

}

void Commandline::addNewCommandText(string commandText) {

	cout << "          nieuwe word toegevoegd aan commandline " << commandText << endl;
	words->push_back(commandText);
}

vector<string>* Commandline::getWords() {
	return words;
}

bool Commandline::GetContainsAppend() {
	return containsAppend;
}
bool Commandline::GetContainsInput() {
	return containsInput;
}
bool Commandline::GetContainsOutput() {
	return containsOutput;
}

void Commandline::SetContainsAppend() {
	containsAppend = true;
}
void Commandline::SetContainsInput() {
	containsInput = true;
}
void Commandline::SetContainsOutput() {
	containsOutput = true;
}

int Commandline::getSizeCommandsWithoutFileDirection() {
	int size = 0;
	bool finish = false;

	//FileDirectionsymbols worden geingnored
	for (vector<string>::const_iterator iter = words->begin(); iter
			!= words->end(); ++iter) {
		if (!finish) {
			if (*iter == ">" || *iter == "<" || *iter == ">>") {
				finish = true;
			} else {
				size++;
			}
		}

	}
	return size;
}

string Commandline::FindPathToOutput() {
	int counter = 0;
	for (vector<string>::const_iterator iter = words->begin(); iter
			!= words->end(); ++iter) {
		if ((*words)[counter] == ">") {
			return (*words)[counter + 1];

		}
		counter++;
	}
	return "Er is geen bestand";
}

string Commandline::FindPathToInput() {
	int counter = 0;
	for (vector<string>::const_iterator iter = words->begin(); iter
			!= words->end(); ++iter) {
		if ((*words)[counter] == "<") {
			return (*words)[counter + 1];
		}
		counter++;
	}
	return "Er is geen bestand";
}

string Commandline::FindPathToAppend() {
	int counter = 0;
	for (vector<string>::const_iterator iter = words->begin(); iter
			!= words->end(); ++iter) {
		if ((*words)[counter] == ">>") {
			return (*words)[counter + 1];
		}
		counter++;
	}
	return "Er is geen bestand";
}
